home *** CD-ROM | disk | FTP | other *** search
/ Australian Personal Computer 2002 November / CD 1 / APC0211D1.ISO / workshop / prog / files / ActivePerl-5.6.1.633-MSWin32.msi / _45203c3be2bf554fccd8b2ee8d5e43c8 < prev    next >
Encoding:
Text File  |  2001-09-04  |  12.2 KB  |  386 lines

  1. /*    pp.h
  2.  *
  3.  *    Copyright (c) 1991-2001, Larry Wall
  4.  *
  5.  *    You may distribute under the terms of either the GNU General Public
  6.  *    License or the Artistic License, as specified in the README file.
  7.  *
  8.  */
  9.  
  10. #ifdef USE_THREADS
  11. #define ARGS thr
  12. #define dARGS struct perl_thread *thr;
  13. #else
  14. #define ARGS
  15. #define dARGS
  16. #endif /* USE_THREADS */
  17.  
  18. #define PP(s) OP * Perl_##s(pTHX)
  19.  
  20. /*
  21. =for apidoc AmU||SP
  22. Stack pointer.  This is usually handled by C<xsubpp>.  See C<dSP> and
  23. C<SPAGAIN>.
  24.  
  25. =for apidoc AmU||MARK
  26. Stack marker variable for the XSUB.  See C<dMARK>.
  27.  
  28. =for apidoc Ams||PUSHMARK
  29. Opening bracket for arguments on a callback.  See C<PUTBACK> and
  30. L<perlcall>.
  31.  
  32. =for apidoc Ams||dSP
  33. Declares a local copy of perl's stack pointer for the XSUB, available via
  34. the C<SP> macro.  See C<SP>.
  35.  
  36. =for apidoc Ams||dMARK
  37. Declare a stack marker variable, C<mark>, for the XSUB.  See C<MARK> and
  38. C<dORIGMARK>.
  39.  
  40. =for apidoc Ams||dORIGMARK
  41. Saves the original stack mark for the XSUB.  See C<ORIGMARK>.
  42.  
  43. =for apidoc AmU||ORIGMARK
  44. The original stack mark for the XSUB.  See C<dORIGMARK>.
  45.  
  46. =for apidoc Ams||SPAGAIN
  47. Refetch the stack pointer.  Used after a callback.  See L<perlcall>.
  48.  
  49. =cut
  50. */
  51.  
  52. #undef SP /* Solaris 2.7 i386 has this in /usr/include/sys/reg.h */
  53. #define SP sp
  54. #define MARK mark
  55. #define TARG targ
  56.  
  57. #define PUSHMARK(p) if (++PL_markstack_ptr == PL_markstack_max)    \
  58.             markstack_grow();            \
  59.             *PL_markstack_ptr = (p) - PL_stack_base
  60.  
  61. #define TOPMARK        (*PL_markstack_ptr)
  62. #define POPMARK        (*PL_markstack_ptr--)
  63.  
  64. #define dSP        register SV **sp = PL_stack_sp
  65. #define djSP        dSP
  66. #define dMARK        register SV **mark = PL_stack_base + POPMARK
  67. #define dORIGMARK    I32 origmark = mark - PL_stack_base
  68. #define SETORIGMARK    origmark = mark - PL_stack_base
  69. #define ORIGMARK    (PL_stack_base + origmark)
  70.  
  71. #define SPAGAIN        sp = PL_stack_sp
  72. #define MSPAGAIN    sp = PL_stack_sp; mark = ORIGMARK
  73.  
  74. #define GETTARGETSTACKED targ = (PL_op->op_flags & OPf_STACKED ? POPs : PAD_SV(PL_op->op_targ))
  75. #define dTARGETSTACKED SV * GETTARGETSTACKED
  76.  
  77. #define GETTARGET targ = PAD_SV(PL_op->op_targ)
  78. #define dTARGET SV * GETTARGET
  79.  
  80. #define GETATARGET targ = (PL_op->op_flags & OPf_STACKED ? sp[-1] : PAD_SV(PL_op->op_targ))
  81. #define dATARGET SV * GETATARGET
  82.  
  83. #define dTARG SV *targ
  84.  
  85. #define NORMAL PL_op->op_next
  86. #define DIE return Perl_die
  87.  
  88. /*
  89. =for apidoc Ams||PUTBACK
  90. Closing bracket for XSUB arguments.  This is usually handled by C<xsubpp>.
  91. See C<PUSHMARK> and L<perlcall> for other uses.
  92.  
  93. =for apidoc Amn|SV*|POPs
  94. Pops an SV off the stack.
  95.  
  96. =for apidoc Amn|char*|POPp
  97. Pops a string off the stack.
  98.  
  99. =for apidoc Amn|NV|POPn
  100. Pops a double off the stack.
  101.  
  102. =for apidoc Amn|IV|POPi
  103. Pops an integer off the stack.
  104.  
  105. =for apidoc Amn|long|POPl
  106. Pops a long off the stack.
  107.  
  108. =cut
  109. */
  110.  
  111. #define PUTBACK        PL_stack_sp = sp
  112. #define RETURN        return PUTBACK, NORMAL
  113. #define RETURNOP(o)    return PUTBACK, o
  114. #define RETURNX(x)    return x, PUTBACK, NORMAL
  115.  
  116. #define POPs        (*sp--)
  117. #define POPp        (SvPVx(POPs, PL_na))        /* deprecated */
  118. #define POPpx        (SvPVx(POPs, n_a))
  119. #define POPn        (SvNVx(POPs))
  120. #define POPi        ((IV)SvIVx(POPs))
  121. #define POPu        ((UV)SvUVx(POPs))
  122. #define POPl        ((long)SvIVx(POPs))
  123. #define POPul        ((unsigned long)SvIVx(POPs))
  124. #ifdef HAS_QUAD
  125. #define POPq        ((Quad_t)SvIVx(POPs))
  126. #define POPuq        ((Uquad_t)SvUVx(POPs))
  127. #endif
  128.  
  129. #define TOPs        (*sp)
  130. #define TOPm1s        (*(sp-1))
  131. #define TOPp1s        (*(sp+1))
  132. #define TOPp        (SvPV(TOPs, PL_na))        /* deprecated */
  133. #define TOPpx        (SvPV(TOPs, n_a))
  134. #define TOPn        (SvNV(TOPs))
  135. #define TOPi        ((IV)SvIV(TOPs))
  136. #define TOPu        ((UV)SvUV(TOPs))
  137. #define TOPl        ((long)SvIV(TOPs))
  138. #define TOPul        ((unsigned long)SvUV(TOPs))
  139. #ifdef HAS_QUAD
  140. #define TOPq        ((Quad_t)SvIV(TOPs))
  141. #define TOPuq        ((Uquad_t)SvUV(TOPs))
  142. #endif
  143.  
  144. /* Go to some pains in the rare event that we must extend the stack. */
  145.  
  146. /*
  147. =for apidoc Am|void|EXTEND|SP|int nitems
  148. Used to extend the argument stack for an XSUB's return values. Once
  149. used, guarantees that there is room for at least C<nitems> to be pushed
  150. onto the stack.
  151.  
  152. =for apidoc Am|void|PUSHs|SV* sv
  153. Push an SV onto the stack.  The stack must have room for this element.
  154. Does not handle 'set' magic.  See C<XPUSHs>.
  155.  
  156. =for apidoc Am|void|PUSHp|char* str|STRLEN len
  157. Push a string onto the stack.  The stack must have room for this element.
  158. The C<len> indicates the length of the string.  Handles 'set' magic.  See
  159. C<XPUSHp>.
  160.  
  161. =for apidoc Am|void|PUSHn|NV nv
  162. Push a double onto the stack.  The stack must have room for this element.
  163. Handles 'set' magic.  See C<XPUSHn>.
  164.  
  165. =for apidoc Am|void|PUSHi|IV iv
  166. Push an integer onto the stack.  The stack must have room for this element.
  167. Handles 'set' magic.  See C<XPUSHi>.
  168.  
  169. =for apidoc Am|void|PUSHu|UV uv
  170. Push an unsigned integer onto the stack.  The stack must have room for this
  171. element.  See C<XPUSHu>.
  172.  
  173. =for apidoc Am|void|XPUSHs|SV* sv
  174. Push an SV onto the stack, extending the stack if necessary.  Does not
  175. handle 'set' magic.  See C<PUSHs>.
  176.  
  177. =for apidoc Am|void|XPUSHp|char* str|STRLEN len
  178. Push a string onto the stack, extending the stack if necessary.  The C<len>
  179. indicates the length of the string.  Handles 'set' magic.  See
  180. C<PUSHp>.
  181.  
  182. =for apidoc Am|void|XPUSHn|NV nv
  183. Push a double onto the stack, extending the stack if necessary.  Handles
  184. 'set' magic.  See C<PUSHn>.
  185.  
  186. =for apidoc Am|void|XPUSHi|IV iv
  187. Push an integer onto the stack, extending the stack if necessary.  Handles
  188. 'set' magic. See C<PUSHi>.
  189.  
  190. =for apidoc Am|void|XPUSHu|UV uv
  191. Push an unsigned integer onto the stack, extending the stack if necessary.
  192. See C<PUSHu>.
  193.  
  194. =cut
  195. */
  196.  
  197. #define EXTEND(p,n)    STMT_START { if (PL_stack_max - p < (n)) {        \
  198.                 sp = stack_grow(sp,p, (int) (n));        \
  199.             } } STMT_END
  200.  
  201. /* Same thing, but update mark register too. */
  202. #define MEXTEND(p,n)    STMT_START {if (PL_stack_max - p < (n)) {        \
  203.                 int markoff = mark - PL_stack_base;        \
  204.                 sp = stack_grow(sp,p,(int) (n));        \
  205.                 mark = PL_stack_base + markoff;        \
  206.             } } STMT_END
  207.  
  208. #define PUSHs(s)    (*++sp = (s))
  209. #define PUSHTARG    STMT_START { SvSETMAGIC(TARG); PUSHs(TARG); } STMT_END
  210. #define PUSHp(p,l)    STMT_START { sv_setpvn(TARG, (p), (l)); PUSHTARG; } STMT_END
  211. #define PUSHn(n)    STMT_START { sv_setnv(TARG, (NV)(n)); PUSHTARG; } STMT_END
  212. #define PUSHi(i)    STMT_START { sv_setiv(TARG, (IV)(i)); PUSHTARG; } STMT_END
  213. #define PUSHu(u)    STMT_START { sv_setuv(TARG, (UV)(u)); PUSHTARG; } STMT_END
  214.  
  215. #define XPUSHs(s)    STMT_START { EXTEND(sp,1); (*++sp = (s)); } STMT_END
  216. #define XPUSHTARG    STMT_START { SvSETMAGIC(TARG); XPUSHs(TARG); } STMT_END
  217. #define XPUSHp(p,l)    STMT_START { sv_setpvn(TARG, (p), (l)); XPUSHTARG; } STMT_END
  218. #define XPUSHn(n)    STMT_START { sv_setnv(TARG, (NV)(n)); XPUSHTARG; } STMT_END
  219. #define XPUSHi(i)    STMT_START { sv_setiv(TARG, (IV)(i)); XPUSHTARG; } STMT_END
  220. #define XPUSHu(u)    STMT_START { sv_setuv(TARG, (UV)(u)); XPUSHTARG; } STMT_END
  221. #define XPUSHundef    STMT_START { SvOK_off(TARG); XPUSHs(TARG); } STMT_END
  222.  
  223. #define SETs(s)        (*sp = s)
  224. #define SETTARG        STMT_START { SvSETMAGIC(TARG); SETs(TARG); } STMT_END
  225. #define SETp(p,l)    STMT_START { sv_setpvn(TARG, (p), (l)); SETTARG; } STMT_END
  226. #define SETn(n)        STMT_START { sv_setnv(TARG, (NV)(n)); SETTARG; } STMT_END
  227. #define SETi(i)        STMT_START { sv_setiv(TARG, (IV)(i)); SETTARG; } STMT_END
  228. #define SETu(u)        STMT_START { sv_setuv(TARG, (UV)(u)); SETTARG; } STMT_END
  229.  
  230. #define dTOPss        SV *sv = TOPs
  231. #define dPOPss        SV *sv = POPs
  232. #define dTOPnv        NV value = TOPn
  233. #define dPOPnv        NV value = POPn
  234. #define dTOPiv        IV value = TOPi
  235. #define dPOPiv        IV value = POPi
  236. #define dTOPuv        UV value = TOPu
  237. #define dPOPuv        UV value = POPu
  238. #ifdef HAS_QUAD
  239. #define dTOPqv        Quad_t value = TOPu
  240. #define dPOPqv        Quad_t value = POPu
  241. #define dTOPuqv        Uquad_t value = TOPuq
  242. #define dPOPuqv        Uquad_t value = POPuq
  243. #endif
  244.  
  245. #define dPOPXssrl(X)    SV *right = POPs; SV *left = CAT2(X,s)
  246. #define dPOPXnnrl(X)    NV right = POPn; NV left = CAT2(X,n)
  247. #define dPOPXiirl(X)    IV right = POPi; IV left = CAT2(X,i)
  248.  
  249. #define USE_LEFT(sv) \
  250.     (SvOK(sv) || SvGMAGICAL(sv) || !(PL_op->op_flags & OPf_STACKED))
  251. #define dPOPXnnrl_ul(X)    \
  252.     NV right = POPn;                \
  253.     SV *leftsv = CAT2(X,s);                \
  254.     NV left = USE_LEFT(leftsv) ? SvNV(leftsv) : 0.0
  255. #define dPOPXiirl_ul(X) \
  256.     IV right = POPi;                    \
  257.     SV *leftsv = CAT2(X,s);                \
  258.     IV left = USE_LEFT(leftsv) ? SvIV(leftsv) : 0
  259.  
  260. #define dPOPPOPssrl    dPOPXssrl(POP)
  261. #define dPOPPOPnnrl    dPOPXnnrl(POP)
  262. #define dPOPPOPnnrl_ul    dPOPXnnrl_ul(POP)
  263. #define dPOPPOPiirl    dPOPXiirl(POP)
  264. #define dPOPPOPiirl_ul    dPOPXiirl_ul(POP)
  265.  
  266. #define dPOPTOPssrl    dPOPXssrl(TOP)
  267. #define dPOPTOPnnrl    dPOPXnnrl(TOP)
  268. #define dPOPTOPnnrl_ul    dPOPXnnrl_ul(TOP)
  269. #define dPOPTOPiirl    dPOPXiirl(TOP)
  270. #define dPOPTOPiirl_ul    dPOPXiirl_ul(TOP)
  271.  
  272. #define RETPUSHYES    RETURNX(PUSHs(&PL_sv_yes))
  273. #define RETPUSHNO    RETURNX(PUSHs(&PL_sv_no))
  274. #define RETPUSHUNDEF    RETURNX(PUSHs(&PL_sv_undef))
  275.  
  276. #define RETSETYES    RETURNX(SETs(&PL_sv_yes))
  277. #define RETSETNO    RETURNX(SETs(&PL_sv_no))
  278. #define RETSETUNDEF    RETURNX(SETs(&PL_sv_undef))
  279.  
  280. #define ARGTARG        PL_op->op_targ
  281.  
  282.     /* See OPpTARGET_MY: */
  283. #define MAXARG        (PL_op->op_private & 15)
  284.  
  285. #define SWITCHSTACK(f,t) \
  286.     STMT_START {                            \
  287.     AvFILLp(f) = sp - PL_stack_base;                \
  288.     PL_stack_base = AvARRAY(t);                    \
  289.     PL_stack_max = PL_stack_base + AvMAX(t);            \
  290.     sp = PL_stack_sp = PL_stack_base + AvFILLp(t);            \
  291.     PL_curstack = t;                        \
  292.     } STMT_END
  293.  
  294. #define EXTEND_MORTAL(n) \
  295.     STMT_START {                            \
  296.     if (PL_tmps_ix + (n) >= PL_tmps_max)                \
  297.         tmps_grow(n);                        \
  298.     } STMT_END
  299.  
  300. #define AMGf_noright    1
  301. #define AMGf_noleft    2
  302. #define AMGf_assign    4
  303. #define AMGf_unary    8
  304.  
  305. #define tryAMAGICbinW(meth,assign,set) STMT_START { \
  306.           if (PL_amagic_generation) { \
  307.         SV* tmpsv; \
  308.         SV* right= *(sp); SV* left= *(sp-1);\
  309.         if ((SvAMAGIC(left)||SvAMAGIC(right))&&\
  310.         (tmpsv=amagic_call(left, \
  311.                    right, \
  312.                    CAT2(meth,_amg), \
  313.                    (assign)? AMGf_assign: 0))) {\
  314.            SPAGAIN;    \
  315.            (void)POPs; set(tmpsv); RETURN; } \
  316.       } \
  317.     } STMT_END
  318.  
  319. #define tryAMAGICbin(meth,assign) tryAMAGICbinW(meth,assign,SETsv)
  320. #define tryAMAGICbinSET(meth,assign) tryAMAGICbinW(meth,assign,SETs)
  321.  
  322. #define AMG_CALLun(sv,meth) amagic_call(sv,&PL_sv_undef,  \
  323.                     CAT2(meth,_amg),AMGf_noright | AMGf_unary)
  324. #define AMG_CALLbinL(left,right,meth) \
  325.             amagic_call(left,right,CAT2(meth,_amg),AMGf_noright)
  326.  
  327. #define tryAMAGICunW(meth,set,shift,ret) STMT_START { \
  328.           if (PL_amagic_generation) { \
  329.         SV* tmpsv; \
  330.         SV* arg= sp[shift]; \
  331.       am_again: \
  332.         if ((SvAMAGIC(arg))&&\
  333.         (tmpsv=AMG_CALLun(arg,meth))) {\
  334.            SPAGAIN; if (shift) sp += shift; \
  335.            set(tmpsv); ret; } \
  336.       } \
  337.     } STMT_END
  338.  
  339. #define FORCE_SETs(sv) STMT_START { sv_setsv(TARG, (sv)); SETTARG; } STMT_END
  340.  
  341. #define tryAMAGICun(meth)    tryAMAGICunW(meth,SETsvUN,0,RETURN)
  342. #define tryAMAGICunSET(meth)    tryAMAGICunW(meth,SETs,0,RETURN)
  343. #define tryAMAGICunTARGET(meth, shift)                    \
  344.     { dSP; sp--;     /* get TARGET from below PL_stack_sp */        \
  345.         { dTARGETSTACKED;                         \
  346.         { dSP; tryAMAGICunW(meth,FORCE_SETs,shift,RETURN);}}}
  347.  
  348. #define setAGAIN(ref) sv = ref;                            \
  349.   if (!SvROK(ref))                                \
  350.       Perl_croak(aTHX_ "Overloaded dereference did not return a reference");    \
  351.   if (ref != arg && SvRV(ref) != SvRV(arg)) {                    \
  352.       arg = ref;                                \
  353.       goto am_again;                                \
  354.   }
  355.  
  356. #define tryAMAGICunDEREF(meth) tryAMAGICunW(meth,setAGAIN,0,(void)0)
  357.  
  358. #define opASSIGN (PL_op->op_flags & OPf_STACKED)
  359. #define SETsv(sv)    STMT_START {                    \
  360.         if (opASSIGN || (SvFLAGS(TARG) & SVs_PADMY))        \
  361.            { sv_setsv(TARG, (sv)); SETTARG; }            \
  362.         else SETs(sv); } STMT_END
  363.  
  364. #define SETsvUN(sv)    STMT_START {                    \
  365.         if (SvFLAGS(TARG) & SVs_PADMY)        \
  366.            { sv_setsv(TARG, (sv)); SETTARG; }            \
  367.         else SETs(sv); } STMT_END
  368.  
  369. /* newSVsv does not behave as advertised, so we copy missing
  370.  * information by hand */
  371.  
  372. /* SV* ref causes confusion with the member variable
  373.    changed SV* ref to SV* tmpRef */
  374. #define RvDEEPCP(rv) STMT_START { SV* tmpRef=SvRV(rv);      \
  375.   if (SvREFCNT(tmpRef)>1) {                 \
  376.     SvREFCNT_dec(tmpRef);                   \
  377.     SvRV(rv)=AMG_CALLun(rv,copy);        \
  378.   } } STMT_END
  379.  
  380. /*
  381. =for apidoc mU||LVRET
  382. True if this op will be the return value of an lvalue subroutine
  383.  
  384. =cut */
  385. #define LVRET ((PL_op->op_private & OPpMAYBE_LVSUB) && is_lvalue_sub())
  386.